package com.wanmait.employment.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.employment.entity.Address;
import com.wanmait.employment.mapper.AddressMapper;
import com.wanmait.employment.service.AddressService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {
    @Resource
    private AddressMapper addressMapper;
    @Override
    public List<Address> provinceList() {
        LambdaQueryWrapper<Address> addressLambdaQueryWrapper=new LambdaQueryWrapper<>();
        addressLambdaQueryWrapper.eq(Address::getLevel,1).eq(Address::getParentId,0);
        List<Address> provinceList=addressMapper.selectList(addressLambdaQueryWrapper);
        return provinceList;
    }

    @Override
    public List<Address> cityList(Integer provinceId) {
        LambdaQueryWrapper<Address> addressLambdaQueryWrapper=new LambdaQueryWrapper<>();
        addressLambdaQueryWrapper.eq(Address::getParentId,provinceId);
        List<Address> cityList=addressMapper.selectList(addressLambdaQueryWrapper);
        return cityList;
    }

    @Override
    public List<Address> areaList(Integer cityId) {
        LambdaQueryWrapper<Address> addressLambdaQueryWrapper=new LambdaQueryWrapper<>();
        addressLambdaQueryWrapper.eq(Address::getParentId,cityId);
        List<Address> areaList=addressMapper.selectList(addressLambdaQueryWrapper);
        return areaList;
    }
}
